<?php
/**
 * Controller is the customized base controller class.
 * All controller classes for this application should extend from this base class.
 */
class Controller extends CController
{
	/**
	 * @var string the default layout for the controller view. Defaults to '//layouts/column1',
	 * meaning using a single column layout. See 'protected/views/layouts/column1.php'.
	 */
	public $layout='//layouts/column1';
	/**
	 * @var array context menu items. This property will be assigned to {@link CMenu::items}.
	 */
	public $menu=array();
	/**
	 * @var array the breadcrumbs of the current page. The value of this property will
	 * be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
	 * for more details on how to specify this property.
	 */
	public $breadcrumbs=array();
	
	public function actions(){
			return array(
				// captcha action renders the CAPTCHA image displayed on the contact page
				'captcha'=>array(
					'class'=>'CCaptchaAction',
					'backColor'=>0xFFFFFF,
				),
				// page action renders "static" pages stored under 'protected/views/site/pages'
				// They can be accessed via: index.php?r=site/page&view=FileName
				'page'=>array(
					'class'=>'CViewAction',
				),
			);
		}
		
    
        function popup($tips,$location='',$target=''){
			$target = ($target == '') ? "window" : $target;
			if(!empty($location))
				$location = $target.".location.href = '$location'";
			else
				$location = "history.back();";
		
			echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
						<script type=\"text/javascript\">\n
							alert('$tips');\n
							$location;\n
						</script>\n";
			exit();		
		}	
		
		/**
		 * 验证是否登陆
		 *
		 * @return unknown
		 */
		function isLogin() {
			if(isset(Yii::app()->session['username'])){
				return true;
			}else{
				$this->popup('请登陆！','./index.php?r=hymember/login'); 
				return false;
			}
		}
		
		
		function yancode($yancode) {
			if($yancode != Yii::app()->session['seccode']){
				 $this->popup('验证码错误！');
				 die;
			}else{
				return true;
			}
		}
		
		
    /**
	 * 获取底部信息
	 */
	  public function getFooterInfo($pid){
	  	$links = ""; 
		$user  = Yii::app()->db->createCommand()
	    ->select('InfoCategoryID, CateName')
	    ->from('hy_b_infocategory')
	    ->where('ParentID=:pid', array(':pid'=>$pid))
	    ->queryAll();
	  
	    if($user){
	    	foreach ($user as $key=>$value){
	    		 $links .=  CHtml::link($value['CateName'], array('/HyBInfo/newsdetail','cateid'=>$value['InfoCategoryID'])); 
	    		 $links .= "<br/>";
	    	}
	    }
	    return $links;
	   
	}
	
	/**
	 * 获取信息类别名
	 *
	 * @param unknown_type $cateid
	 * @return unknown
	 */
	public function  getCateName($cateid){
		$catename = Yii::app()->db->createCommand()
	    ->select('CateName')
	    ->from('hy_b_infocategory')
	    ->where('InfoCategoryID=:cateid', array(':cateid'=>$cateid))
	    ->queryRow();
	    return $catename['CateName'];
	}
		
	
     /***
 	 * 处理URL字符串
 	 * @arr Array $arr
 	 * @return Array $str
 	 */
 	public function handleUrl($arr = array()){
 	   $str = '';
 	   if($arr){
 	   	  foreach($arr as $key => $value){
 	   	  	 $str[] = $key.'='.$value;
 	   	  }
 	   }
 	   $str =  implode("&", $str);
 	   return $str;
 	}
 	
 	/**
 	 * 
 	 * 删除不需要的数组
 	 * @param Array $array
 	 * @param Array $delarr
 	 */
	public function unsetArray($array,$delarr){
		foreach ($array as $bkey=>$bvalue){
			foreach ($delarr as $key=>$value){
				if($value == $bkey){
				unset($array[$bkey]);		
			    }
		     }
	    }
		return $array;
	}
	
}